import { Controller } from '@nestjs/common';
import { ToolResponse } from '../type';
import { Tool } from '@rekog/mcp-nest';
import axios from 'axios';
import { z } from 'zod';

@Controller('daily-news')
export class NewsController {
  @Tool({
    name: 'daily-news',
    description: '每日新闻、60s'
  })
  async exec({}): Promise<ToolResponse> {
    const res = await axios.get('https://60s-api.viki.moe/v2/60s').catch((err) => err);

    if (res.status !== 200) {
      return {
        isError: true,
        content: [
          {
            type: 'text',
            text: '获取失败'
          }
        ]
      };
    }

    return {
      content: [
        {
          type: 'text',
          text: JSON.stringify({
            date: res.data.data.date,
            news: res.data.data.news,
            link: res.data.data.link
          })
        }
      ]
    };
  }
}
